import 'package:flutter/material.dart';

class SwitchDemo extends StatefulWidget {
  SwitchDemo({Key key}) : super(key: key);

  @override
  _SwitchDemoState createState() => _SwitchDemoState();
}

class _SwitchDemoState extends State<SwitchDemo> {
  bool _switchCurrentState = false;

  void _switchChangeState(bool value) {
    setState(() {
      _switchCurrentState = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SwitchDemo'),
        elevation: 0.0,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          SwitchListTile(
            value: _switchCurrentState,
            onChanged: _switchChangeState,
            title: Text('是否打开'),
            subtitle: Text('description'),
            secondary: Icon(
                _switchCurrentState ? Icons.visibility : Icons.visibility_off),
            selected: _switchCurrentState,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                '${_switchCurrentState ? '😁' : '😢'}',
                style: TextStyle(fontSize: 32.0),
              ),
              Switch(
                value: _switchCurrentState,
                onChanged: _switchChangeState,
                activeColor: Colors.purple,
              )
            ],
          )
        ],
      ),
    );
  }
}
